﻿using AsposeHelper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QD.LopPlat.UI
{
    public delegate void OpenFileClosedEvent(object data);
    public partial class OpenFileDialogMag : Form
    {
        public event OpenFileClosedEvent ClosedEvent;
        private object data;

        private string fileFilter;
        public OpenFileDialogMag(string fileFilter)
        {
            InitializeComponent();
            this.fileFilter = fileFilter;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (ClosedEvent != null)
            {
                ClosedEvent(data);
            }
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog fileDialog = new OpenFileDialog();
                fileDialog.Filter = fileFilter;

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    data = CellsHelper.ExportDataTable(fileDialog.FileName, 0);
                    this.label1.Text = "数据处理完成，请点击\"完成\"按钮！";
                    this.label1.Visible = true;
                }
            }
            catch (Exception ex)
            {
                Tools.PromptHelper.Prompt(ex);
            }
        }
    }
}
